Math.round = (function() {
	var oldRound = Math.round;
	return function(number, precision) {
		precision = Math.abs(parseInt(precision)) || 0;
		var coefficient = Math.pow(10, precision);
		return oldRound(number*coefficient)/coefficient;
	};
})();

var priceControl = {
	base:0.010,
	_format:{
		"decimals":2,
		"dec_point":".",
		"thousands_sep":"",
		"fonttend_decimal_type":0,
		"fonttend_decimal_remain":2,
		"sign":""
	},
	format:function(num){
		var part;
		if(!num && num !== 0)return;
		var num = parseFloat(num);
		
		num = Math.round(num, this._format.decimals)+'';
		var p =num.indexOf('.');
		if(p<0){
			p = num.length;part = '';
		}else{
			part = num.substr(p+1);
		}
		while(part.length<this._format.decimals){part+='0';}
		var c=[];
		while(p>0){
			if(p>2){
				c.unshift(num.substr(p-=3,3));
			} else {
				c.unshift(num.substr(0,p));
				break;
			}
		}
		if(!part){this._format.dec_point='';}
		return (this._format.sign||"")+c.join(this._format.thousands_sep)+this._format.dec_point+part;
	}
};

function strlen(str){
	var len=0;
	for(var i=0;i<str.length;i++){
		if(str.charCodeAt(i)>255){
			len+=2;
		}else{
			++len;
		}
	}
	return len;
}

function copyToClipBoard(txt) {
    if (window.clipboardData) {
        window.clipboardData.clearData();
        window.clipboardData.setData("Text", txt);
        return true;

    } else if (navigator.userAgent.indexOf("Opera") != -1) {
        window.location = txt;
        return true;
        
    } else if (window.netscape) {
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        } catch (e) {
            alert("\u88AB\u6D4F\u89C8\u5668\u62D2\u7EDD\uFF01\n\u8BF7\u5728\u6D4F\u89C8\u5668\u5730\u5740\u680F\u8F93\u5165'about:config'\u5E76\u56DE\u8F66\n\u7136\u540E\u5C06'signed.applets.codebase_principal_support'\u8BBE\u7F6E\u4E3A'true'");
            return false;
        }

        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip) {
        	return false;
        }

        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans) {
        	return false;
        }

        trans.addDataFlavor("text/unicode");
        var str = new Object;
        var len = new Object;
        var str = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString);
        var copytext = txt;
        str.data = copytext;
        trans.setTransferData("text/unicode", str, copytext.length * 2);
        var clipid = Components.interfaces.nsIClipboard;
        if (!clip) {
            return false;
        }
        clip.setData(trans, null, clipid.kGlobalClipboard);
        return true;
    }
    
    return false;
}